import { request, service } from '@/utils/request'
import type { ArticleDetailInfo, PublishArticleParams } from '@/types/publish'

/**
 * 上传图片API
 */
export const uploadImageAPI = (file: FormData) => {
  return request<{ url: string }>('/v1_0/upload', 'POST', file)
}


/**
 * 发布文章API
 */
export const publishArticleAPI = (draft: boolean, params: PublishArticleParams) => {
  return service.request({
    url: '/v1_0/mp/articles',
    method: 'POST',
    data: params,
    params: { draft: draft },
  })
}

/**
 * 获取文章详情API
 */
export const getArticleDetailInfoAPI = (id: string) => {
  return request<ArticleDetailInfo>(`/v1_0/mp/articles/${id}`)
}

/**
 * 更新文章API
 */
export const updateArticleAPI = (id: string, data: ArticleDetailInfo, draft: boolean) => {
  return service.request({
    url: `/v1_0/mp/articles/${id}`,
    method: 'PUT',
    data,
    params: { draft: draft },
  })
}
